<template>
	<view class="np-goods-list">
		<view class="np-goods-container">
			<view class="np-goods-box shadow" v-for="(item,index) in goodsList" :key="index" v-if="(index+1)%2!=0" @click="navTo(item)">
				<view class="goods-image-box">
					<image lazy-load="true" :src="item.image" class="goods-image" mode="widthFix" />
				</view>
				<view class="np-goods-content">
					<view class="np-goods-title more-line margin-bottom-xs">
						<text v-for="(item,index) in item.tags" :key="index" class="np-goods-tag" :class="item.color ? 'bg-' + item.color : 'bg-red'">{{item.name}}</text>
						<text class="pd-left">{{item.title}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="np-goods-container">
			<view class="np-goods-box shadow" v-for="(item,index) in goodsList" :key="index" v-if="(index+1)%2==0" @click="navTo(item)">
				<view class="goods-image-box">
					<image lazy-load="true" :src="item.image" class="goods-image" mode="widthFix" />
				</view>
				<view class="np-goods-content">
					<view class="np-goods-title more-line margin-bottom-xs">
						<text v-for="(item,index) in item.tags" :key="index" class="np-goods-tag" :class="item.color ? 'bg-' + item.color : 'bg-red'">{{item.name}}</text>
						<text class="pd-left">{{item.title}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			goodsList: {
				type: Array,
				default: ()=>{
					return []
				}
			}
		},
		methods: {
			navTo(item) {
				let url = "/pages/item/tb?id=" + item.itemid;
				if (item.api === 'jd') {
					url = "/pages/item/jd?id=" + item.itemid;
				} else if (item.api === 'pdd') {
					url = "/pages/item/pdd?id=" + item.itemid;
				}
				uni.navigateTo({
					url: url
				});
			}
		}
	}
</script>

<style>
	.np-goods-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0 20rpx;
	}
	
	.np-goods-container {
		width: 49%;
		margin-top: 20rpx;
	}
	
	.np-goods-box {
		width: 100%;
		display: flex;
		flex-direction: column;
		border-radius: 16rpx;
		overflow: hidden;
		background: #FFFFFF;
		margin-bottom: 16rpx;
	}
	
	.goods-image-box {
		width: 100%;
		position: relative;
		overflow: hidden;
	}
	
	.goods-image {
		width: 100%;
	}
	
	.image-top-box {
		position: absolute;
		top: 0;
		left: 0;
		display: flex;
		flex-direction: column;
		align-items: flex-start;
	}
	
	.tip-box {
		line-height: 30rpx;
	}
	
	.tip-tags {
		line-height: 30rpx;
		padding: 0 10rpx;
		font-size: 20rpx;
		border-top-right-radius: 6rpx;
		border-bottom-right-radius: 6rpx;
	}
	
	.border-r {
		border-top-right-radius: 12rpx;
	}
	
	.image-bottom-box {
		position: absolute;
		bottom: 0;
		width: 100%;
		display: flex;
		flex-direction: column;
	}
	
	.tip-mall {
		width: 100%;
		padding: 5rpx 10rpx;
		font-size: 20rpx;
		background-color: rgba(0, 0, 0, 0.5);
	}
	
	.np-goods-content {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 15rpx;
	}
	
	.np-goods-title {
		font-size: 30rpx;
		line-height: 40rpx;
		position: relative;
	}
	
	.np-goods-tag {
		font-size: 22rpx;
		font-weight: 600;
		padding: 0 8rpx;
		height: 30rpx;
		line-height: 30rpx;
		border-radius: 6rpx;
		margin-right: 5rpx;
		vertical-align: middle;
		position: relative;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		margin-top: -6.09rpx;
	}
	
	.pd-left {
		padding-left: 5rpx;
	}
	
	/*多行文本溢出省略号*/
	.more-line {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		transition: all linear 0.2s;
	}
</style>
